package cn.ym.system.controller;

import cn.ym.basic.util.AjaxResult;
import cn.ym.basic.util.PageList;
import cn.ym.system.domain.Systemdictionarydetail;
import cn.ym.system.domain.Systemdictionarytype;
import cn.ym.system.query.SystemdictionarytypeQuery;
import cn.ym.system.service.ISystemdictionarytypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 接口类：员工
 */
@RestController//json+controller
//@Controller
//@ResponseBody
@RequestMapping("/systemdictionarytype")
@Api(value = "员工接口类" ,description = "处理员工的所有请求")
public class SystemdictionarytypeController {

    @Autowired
    private ISystemdictionarytypeService systemdictionarytypeService;

    //写一个接口/方法：1.请求方式 2.请求参数 3.请求地址 4.返回数据格式
    /**
     * 接口：查询所有对象
     * @return
     */
    @GetMapping //Get http://localhost:8080/systemdictionarytype
    @ApiOperation(value = "查询所有对象")
    public List<Systemdictionarytype> findAll(){

        return  systemdictionarytypeService.findAll();
    }
    /**
     * 接口：查询单个对象
     * @param id
     * @return
     */
    @GetMapping("/{id}") //Get http://localhost:8080/systemdictionarytype/1
    @ApiOperation(value = "查询单个对象")
    public Systemdictionarytype findOne(@PathVariable("id") Long id){
        return systemdictionarytypeService.findOne(id);
    }

    /**
     * 接口：分页查询或高级查询
     * @param
     * @return
     */
    @PostMapping//Post http://localhost:8080/systemdictionarytype  对象
    @ApiOperation(value = "分页查询或高级查询")
    public PageList<Systemdictionarytype> queryPage(@RequestBody SystemdictionarytypeQuery systemdictionarytypeQuery){
    return systemdictionarytypeService.queryPage(systemdictionarytypeQuery);
    }

    /**
     * 接口：删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")//Delete http://localhost:8080/systemdictionarytype/1
    @ApiOperation(value = "删除")
    public AjaxResult delete(@PathVariable("id")Long id ){
        try {
            systemdictionarytypeService.delete(id);
            return  new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return  new AjaxResult(false,"删除失败");
        }
    }

    /**
     * 接口：添加或修改
     * @param systemdictionarytype
     * @return
     */
    @PutMapping//Put http://localhost:8080/systemdictionarytype/{对象}
    @ApiOperation(value = "添加或修改")
    public AjaxResult addOrUpdate(@RequestBody Systemdictionarytype systemdictionarytype ){
        try {
            if (systemdictionarytype.getId() == null){//没有id，执行新增
                systemdictionarytypeService.add(systemdictionarytype);
            }else {//有id，执行修改

                systemdictionarytypeService.update(systemdictionarytype);
            }
            //返回无参
            return  new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            //返回有参
            return  new AjaxResult(false,"操作失败");
        }
    }

    /**
     * 接口：批量删除
     * @param ids
     * @return
     */
    @PatchMapping //Patch http://localhost:8080/systemdictionarytype/ids
    @ApiOperation(value = "批量删除")
    public AjaxResult patchDelete(@RequestBody List<Long> ids ){
        try {
            systemdictionarytypeService.patchDelete(ids);
            return  new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return  new AjaxResult(false,"批量删除失败");
        }
    }

    @GetMapping("/loadquery/{id}") //Get http://localhost:8080/systemdictionarydetail/1
    public List<Systemdictionarydetail> loadquery(@PathVariable("id") Long id){
        System.out.println(id);

        return systemdictionarytypeService.loadquery(id);
    }


}
